package com.blb.controller;

import com.blb.dto.ZZhubo;
import com.blb.dto.ZZhuboExample;
import com.blb.service.ZZhuboService;
import com.blb.utils.LayUIDataTable;
import com.blb.utils.Status;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/search")
@CrossOrigin
public class SearchController {

    @Autowired
    private ZZhuboService zZhuboService;

    //搜索
    @RequestMapping("/sear/{se}/{page}/{pagesize}")
    @ResponseBody
    public LayUIDataTable search(Model model,@PathVariable("se") String se,@PathVariable("page") int page,@PathVariable("pagesize") int pageSize){
        LayUIDataTable dt = new LayUIDataTable();
        ZZhuboExample zZhuboExample = new ZZhuboExample();
        ZZhuboExample.Criteria criteria = zZhuboExample.createCriteria();
        criteria.andNichenLike("%"+se+"%");           //加入名称查询条件
        ZZhuboExample.Criteria criteria1 = zZhuboExample.createCriteria();
        criteria1.andRoomidEqualTo(se);                      //加入房间号查询条件
        zZhuboExample.or(criteria1);                        //条件合并
        PageHelper.startPage(page,pageSize);                //分页
        List<ZZhubo> zZhubos = zZhuboService.selectByExample(zZhuboExample);
        PageInfo pageInfo = new PageInfo(zZhubos);
        dt.setData(pageInfo);
        dt.setCode(Status.SUCCESS);
        dt.setCount(0);
        dt.setMsg("搜索成功！");
        return dt;
    }
}
